// import axios from '@/utils/request.js'
import request from '@/utils/request'

export const loginAPI = ({ mobile, code }) =>
  request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: mobile,
      code: code
    }
  })

export const getUserChannelListAPI = () =>
  request({
    url: '/v1_0/user/channels'

  })

/***
 *获取频道
 */
export const getChannelListAPI = () =>
  request({
    url: '/v1_0/channels'
  })
// 设置用户的频道（重置式）
export const setUserChannelsAPI = (channelArr) =>
  request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channelArr
    }
  })

// 获取文章列表数据
export const getArticleListAPI = ({ channel_id, timestamp = new Date() }) =>
  request({
    url: '/v1_0/articles',

    params: {
      channel_id,
      timestamp
    }
  })

// 首页反馈不喜欢文章
export const disliskArticleAPI = (artId) =>
  request({
    url: '/v1_0/article/dislikes',
    method: 'POST',

    data: {
      target: artId
    }
  })

// 首页反馈-举报文章
export const reportArticleAPI = ({ artId, type }) =>
  request({
    url: '/v1_0/article/reports',
    method: 'POST',

    data: {
      target: artId,
      type: type,
      remark: '举报了也没用'
    }
  })

// 获取联想建议（自动补全）
export const suggestListAPI = (keyWord) =>
  request({
    url: '/v1_0/suggestion',
    params: {
      q: keyWord
    }

  })

// 获取搜索结果
export const searchListAPI = ({ keyWord, page = 1, per_page = 10 }) =>
  request({
    url: '/v1_0/search',
    params: {
      q: keyWord,
      page: page,
      per_page: per_page
    }
  })
  //  获取文章详情
export const getArticleDetailAPI = ({ artId }) => request({
  url: `/v1_0/articles/${artId}`
})
// 对文章点赞
export const likeArticleAPI = (artId) => request({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target: artId
  }
})
// 取消对文章点赞
export const unLikeArticleAPI = (artId) => request({
  url: `/v1_0/article/likings/${artId}`,
  method: 'DELETE'

})
// 删除用户指定的频道
export const removeChannelAPI = (channleId) =>
  request({
    url: `/v1_0/user/channels/${channleId}`,
    method: 'DELETE',
    headers: {
      'Content-Type': 'application / x - www - form - urlencoded'
    }
  })

// 获取用户关注
export const followedAuthorAPI = (authorId) =>
  request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: authorId
    }
  })
  // 取关用户
export const unFollowedAuthorAPI = (authorId) =>
  request({
    url: `/v1_0/user/followings/${authorId}`,
    method: 'DELETE'

  })
  // 获取评论或评论回复
export const getCommentsListAPI = ({ artId, offset = null, limit = 1 }) =>
  request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset: offset,
      limit: limit
    }
  })
  // 对评论或评论回复点赞
export const likeCommentsAPI = (commentId) =>
  request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: commentId
    }
  })
  // 取消对评论或评论回复点赞

export const unLikeCommentsAPI = (commentId) =>
  request({
    url: `/v1_0/comment/likings/${commentId}`,
    method: 'DELETE'

  })
  // 发布评论
export const sendCommentAPI = ({ target, content, artId = null }) => {
  const obj = {
    target: target,
    content: content
  }
  if (artId !== null) {
    obj.art_id = artId
  }

  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}

// 获取 -用户信息（包含关注,动态,粉丝数量）
export const getUserInfoAPI = () =>
  request({
    url: '/v1_0/user'
  })
  // 获取-个人资料(生日,用户名,头像)
export const getProfileAPI = () =>
  request({
    url: '/v1_0/user/profile'
  })
  // 更新  个人头像
export const uploadHeadImgAPI = (fd) =>
  request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fd
  })
